using System.Collections.Generic;
using System.Text;
using OracleInternal.Common;

namespace OracleInternal.SqlAndPlsqlParser.LocalParsing
{
	public class OracleLpStatement : OracleLpStatementElement
	{
		protected OracleLpTextFragment m_vText;

		protected List<OracleLpBindParameter> m_vBindParameters;

		protected bool m_vHasReturningClause;

		internal IOracleMetadata m_vODPContext;

		internal List<OracleLpQteNamedObject> m_vNamedObjectsReferences;

		internal override OracleLpStatementElementType ElementType => OracleLpStatementElementType.Statement;

		public virtual OracleLpStatementType StatementType => OracleLpStatementType.Unknown;

		public OracleLpTextFragment Text => m_vText;

		public List<OracleLpBindParameter> BindParameters => m_vBindParameters;

		public bool HasBindParameters
		{
			get
			{
				if (m_vBindParameters != null)
				{
					return m_vBindParameters.Count != 0;
				}
				return false;
			}
		}

		public bool HasReturningClause
		{
			get
			{
				return m_vHasReturningClause;
			}
			internal set
			{
				m_vHasReturningClause = value;
			}
		}

		internal object ODPContext => m_vODPContext;

		internal List<OracleLpQteNamedObject> NamedObjectsReferences => m_vNamedObjectsReferences;

		internal OracleLpStatement(OracleLpTextFragment text, IOracleMetadata odpContext)
			: base(null)
		{
			m_vText = text;
			m_vODPContext = odpContext;
		}

		internal void AddParameter(OracleLpBindParameter param)
		{
			if (m_vBindParameters == null)
			{
				m_vBindParameters = new List<OracleLpBindParameter>();
			}
			m_vBindParameters.Add(param);
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder(256);
			ToString(stringBuilder);
			return stringBuilder.ToString();
		}

		internal override void ToString(StringBuilder sb)
		{
			sb.Append("Statement Type:  ");
			sb.Append(StatementType.ToString());
			sb.Append('\n');
			sb.Append("Text:  ");
			sb.Append(Text);
			sb.Append('\n');
			sb.Append("Bind parameters: ");
			if (m_vBindParameters == null)
			{
				sb.Append("None\n");
			}
			else
			{
				sb.Append(m_vBindParameters.Count);
				sb.Append('\n');
				m_vBindParameters.ForEach(delegate(OracleLpBindParameter bp)
				{
					sb.Append(bp.ToString());
				});
			}
			sb.Append("Has RETURNING clause:  ");
			sb.Append(m_vHasReturningClause);
			sb.Append("\n\n");
		}
	}
}
